﻿<link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="/easyui/demo.css">
<link rel="stylesheet" type="text/css" href="/easyui/base.css">
<link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
<script type="text/javascript" src="/easyui/jquery.min.js"></script>
<script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>

<body class="easyui-layout">

<!-- 遮罩层 -->
<div id='PageLoadingTip' style="position: absolute; z-index: 1000; top: 0px; left: 0px; width: 100%; height: 100%; background: #222222; text-align: center;">
    <h1 style="top: 48%; position: relative;"><img src="/media/image/loading.gif"></h1>
</div>

<div class="easyui-layout" style="height:100px,padding-bottom:0px,border: false"  data-options="fit:true" id="conent-layout">
    <span hidden id="hidden_id"></span>
    <div data-options="region:'center',border:false" style="height: auto">
        <div class="easyui-layout" style="width:100%;height:100%;">
            <!-- 主表  -->
            <table id="log_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
                   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/log-list/1/20',
                               method:'get',
                               toolbar:'#tb',
                               loadMsg : '数据加载中',
                               <#--fitColumns : true,-->
                               onDblClickCell:onDblClickCellFunc,
                               onAfterEdit:function(index,row){
                                  var id = row.id;
                                var title = row.logTitle;
                                var desc = row.logDescription;
                                var type = row.logType;
                                var logWorkload = row.logWorkload;
                                    updateActions(id,title,desc,type,logWorkload);
                                 },
           showFooter: true" >
                <thead data-options="frozen:true">
                    <tr>
                        <th data-options="field:'uploadFlag',width:30,formatter:formatPush"></th>
                        <th data-options="field:'logTitle', width:120,formatter:formatSystemType,editor:{
                            type:'combobox',
                            options:{
                                valueField:'value',
                            textField:'key',
                            url : '/constants/system-types',
                                editable: true,
                                required:true,
                                missingMessage:'请选择系统名称'
                            }
                        }" sortable="true">系统名称</th>
                        <th data-options="field:'logDescription', width:200,align:'center',editor:{
                            type:'validatebox',
                            options:{
                                required:true,
                                missingMessage:'请输入日志描述'
                            }
                        }">基本描述</th>
                        <th data-options="field:'logWorkload',width:90 ,align:'center',editor:{
                           type:'validatebox',
                           options:{
                                required:true,
                                validType:'isWorkLoad',
                                missingMessage:'请输入工作量'
                           }
                        }">工作量</th>
                        <th data-options="field:'logContent',width:60,formatter:formatDesc,align:'center'">
                            日志内容
                        </th>
                        <th data-options="field:'logType', width:90,align:'center',formatter:formatLogType,editor:{
                                type:'combobox',
                                options:{
                                valueField:'value',
                                textField:'key',
                                url : '/constants/log-types',
                                    editable: true,
                                    required:true,
                                    missingMessage:'请选择日志类型'
                                }
                            }">日志类型</th>
                        <th data-options="field:'logCommitterId',formatter:formatCommitter" >提交人员</th>
                        <th data-options="field:'belongToBusinessUnit',formatter:function(value, row, index){
                        if(value=='groupA'){
                            return '研究一组'
                        }else if(value=='groupB'){
                             return '研究二组'
                        }else if(value=='groupC'){
                             return '研究三组'
                        }else if(value=='groupD'){
                             return '室主任'
                        }
                    },width:120">所属事业部</th>
                        <th data-options="field:'belongToDepartment',width:120">所属组别</th>
                    </tr>
                </thead>
                <thead>
                <tr>
                    <th data-options="field:'logContractType',width:120">合同分类</th>
                    <th data-options="field:'logJobType',width:120">工作分类</th>
                    <th data-options="field:'logRole',width:90">角色</th>

                    <th data-options="field:'logServiceType',width:90">服务类型</th>
                    <#--<th data-options="field:'logContent'" hidden></th>-->
                    <th data-options="field:'deleteFlag'" hidden></th>
                </thead>
            </table>
        </div>
    </div>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        事件描述:<input class="easyui-textbox" id="desc" style="width:120px" >
        系统名称:
		<input class="easyui-combobox" name="language"id="system-type"
			   data-options="
				url : '/constants/system-types',
				method: 'get',
				valueField:'value',
				textField:'key'
				">
		日志类型:
        <input class="easyui-combobox" name="language"id="log-type"
               data-options="
				url : '/constants/log-types',
				method: 'get',
				valueField:'value',
				textField:'key'
				">
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <div>
        <#list buttons as buttons>
            <a href="#" class="easyui-linkbutton" iconCls="${buttons.iconCls}" id="${buttons.buttonId}">${buttons.buttonName}</a>
        </#list>
    </div>
</div>

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<!-- 新增验证 -->
<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, {
        isWorkLoad: {
            validator: function (value) {
                var workLoad = /^[0-9]+\.{0,1}[0-9]{0,2}$/;
                if (workLoad.test(value)) {
                    return true;
                } else {
                    return false;
                }
            },
            message: '整数或者小数'
        },
        isEmail: {
            validator: function (_4eb) {
                return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(_4eb);
            }, message: "请输入正确的邮箱"
        }
    });
</script>

<!-- 按钮操作 -->
<script type="text/javascript">
    //新增
    $("#add").click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if (row){
            var index = $('#log_table').datagrid('getRowIndex', row);
        } else {
            index = 0;
        }
        $('#log_table').datagrid('insertRow', {
            index: index,
            row:{
                deleteFlag:'N',
                belongToBusinessUnit:'信息化事业部',
                belongToDepartment:'应用研发二室'
            }
        });
        $('#log_table').datagrid('selectRow',index);
        $('#log_table').datagrid('beginEdit',index);
    })

    //保存
    $("#save").click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if (row){
            var index = $('#log_table').datagrid('getRowIndex', row);
        } else {
            index = 0;
        }
        $('#log_table').datagrid('endEdit',index);
    })

    //编辑
    $("#edit").click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if (row){
            var index = $('#log_table').datagrid('getRowIndex', row);
            $('#log_table').datagrid('selectRow',index);
            $('#log_table').datagrid('beginEdit',index);
        } else {
            layer.msg('请选择需要编辑的日志');
        }

    })
    //删除
    $("#delete").click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if(!row){
            layer.msg('请选择需要删除的日志');
        }else{
            $.messager.confirm('删除信息','确定删除日志名称为:'+row.logTitle+"吗?",function(r){
                if (r){
                    var time = new Date();
                    $.ajax({
                        url :'/log-ins-upd-del',
                        data : {id :row.id,flag:'Y'},
                        async : true,
                        success : function(){
                            $('#log_table').datagrid('reload');
                        }
                    });
                }
            });
        }
    })
    //上传图片
    $('#upload').click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if(!row){
            layer.msg('请选择需要上传截图的日志');
        }else {
            var id = row.id;
            var url = '/uploadSolution/' + row.id;
            var index = layer.open({
                type: 2,
                skin: 'layui-layer-rim', //加上边框
                area: ['720px', '481px'], //宽高
                content: url
            });
        }
    })
    //查看图片
    $('#search').click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if(!row){
            layer.msg('请选择需要查看截图的日志');
        }else {
            var id = row.id;
            $.ajax({
                url: '/log-has-images/' + id,
                async: false,
                success: function (result) {
                    if(result=='ZERO'){
                        layer.msg('没有图片，请先上传');
                    }else{
                        var url =  '/log-images-show/'+id;
                        var index = layer.open({
                            type: 2,
                            title: '图片展示',
                            content: url
                        });
                        layer.full(index);
                    }

                }
            });
        }
    });
    //搜索
    $("#searchByParameter").click(function(){
        var system = $("#system-type").val();
        var desc = $("#desc").val();
        var log = $("#log-type").val();
        var handler = '/log-list/1/20?system='+system+"&desc="+desc+"&log="+log;
        $('#log_table').datagrid('options').url = handler;
        $('#log_table').datagrid('reload');
    });
    
    //下载
    $('#export').click(function () {
        var desc = $('#desc').val();
        var system = $('#system-type').val();
        var log = $('#log-type').val();
        layer.msg('下载中');
        window.location.href='/log-download?desc='+desc+'&system='+system+'&log='+log;
    })

    $('#push').click(function () {
        var row = $('#log_table').datagrid('getSelected');
        if(!row){
            layer.msg('请选择需要共享/取消共享的日志');
        }else{
            $.messager.confirm('操作日志','确定操作日志名称为:'+row.logTitle+"的日志吗?",function(r){
                if (r){
                    var time = new Date();
                    $.ajax({
                        url :'/log-ins-upd-del',
                        data : {id :row.id,flag:'P'},
                        async : true,
                        success : function(){
                            $('#log_table').datagrid('reload');
                        }
                    });
                }
            });
        }

    });
</script>

<!-- 增修操作 -->
<script type="text/javascript">
    function updateActions(id,title,desc,type,logWorkload){
        var index = '';
        var tm = new Date();
        $.ajax({
            url : '/log-ins-upd-del',
            data : {id:id,logTitle:title,logDescription:desc,logType:type,logWorkload:logWorkload},
            async : true,
            type : 'post',
            beforeSend: function (request) {
                index = layer.load(1, {
                    shade: [0.5,'#ffffcc'] //0.1透明度的白色背景
                });
            },
            success :function () {
                layer.close(index);
                $('#log_table').datagrid('reload');
            }
        })
    }
</script>

<!-- 数据格式化 -->
<script type="text/javascript">
    function formatPush(val ,row) {
        if(val=='P'){
            return '<i class="Hui-iconfont">&#xe6dc;</i>'
        }else if(val == 'N'){
            return '<i class="Hui-iconfont">&#xe631;</i>'
        }
    }
    function formatSystemType(val ,row){
        if(val=='cx'){
            return '产销系统'
        }
        if(val=='quintiq'){
            return '坤帝科计划系统'
        }
    }
    function formatLogType(val ,row){
		if(val=='activeOperation'){
		    return '主动运维'
		}
		if(val=='8011'){
            return '8011运维'
		}
		if(val=='develop'){
            return '功能开发'
		}
	}
	function formatDesc(val,row,index){
        if(typeof(val)=="undefined"){
            return '';
        }else{
            return '<a href="#" title="'+val+'" class="easyui-tooltip">详细内容</a>'
        }
    }
    function formatCommitter(val,row,index) {
        if(typeof(val)=="undefined"){
            return '';
        }else{
            var rsult = 'aa';
            $.ajax({
                url : '/localUserInfo-nickname/'+val,
                async :false,
                type : 'post',
                success : function(data){
                    rsult = data;
                }
            })
            return rsult;
        }
    }

</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#log_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
                var system = $("#system-type").val();
                var desc = $("#desc").val();
                var log = $("#log-type").val();
				var handler = '/log-list/'+pageNumber+"/"+pageSize+'?system='+system+"&desc="+desc+"&log="+log;
				$('#log_table').datagrid('options').url = handler;
				$('#log_table').datagrid('reload');
			}
		});
	})
</script>

<script type="text/javascript">
    //双击
    function onDblClickCellFunc(rowIndex, row) {
        var row = $('#log_table').datagrid('getSelected');
        if(row){
            var id = row.id;
            var logContent = row.logContent;
            $('#hidden_id').html(id);
            layer.prompt({title: '完成工作内容', value:logContent,formType: 2,maxlength: 2000}, function(text, index){
                layer.close(index);
                var id = $('#hidden_id').html();
                var content = text;
                var url = '/log-ins-upd-del';
                $.ajax({
                    url : url,
                    data :{id:id,flag:'D',content:content,time:new Date()},
                    async: true,
                    type : 'post',
                    success :function () {
                        var p = $('#log_table').datagrid('getPager');
                        var options = p.data("pagination").options;
                        var curr = options.pageNumber;
                        var handler = '/log-list/'+curr+"/20";
                        $('#log_table').datagrid('options').url = handler;
                        $('#log_table').datagrid('reload');
                        layer.msg('保存成功');
                    }
                })
            });
        }
    }
</script>

<!-- 遮罩层 -->
<script type="text/javascript">
    function _PageLoadingTip_Closes() {
        $("#PageLoadingTip").fadeOut("normal", function () {
            $(this).remove();
        });
    }
    var _pageloding_pc;
    $.parser.onComplete = function () {
        if (_pageloding_pc) clearTimeout(_pageloding_pc);
        _pageloding_pc = setTimeout(_PageLoadingTip_Closes, 1000);
    }
</script>